home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PKTMODE.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  5KB  |  231 lines

  1. version    equ    2
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet mode version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    ?,?,?,?
  44. packet_mode    dw    -1,?
  45.  
  46. handle        dw    0
  47. this_mode    dw    ?
  48. bogus_type    db    0,0        ;totally bogus type code.
  49.  
  50. signature    db    'PKT DRVR',0
  51. signature_len    equ    $-signature
  52. no_signature_msg    db    "No packet driver at that address",'$'
  53. usage_msg    db    "usage: pktmode <packet_int_no> [<mode>]",'$'
  54. bad_handle_msg    db    "Bad handle error",'$'
  55. bad_mode_msg    db    "Bad mode error",'$'
  56. bad_error_msg    db    "Unknown error",'$'
  57.  
  58. not_implemented    db    "no      ",'$'
  59. current_mode    db    "current ",'$'
  60. two_spaces    db    "yes     ",'$'
  61.  
  62. mode_names    dw    mode_1_msg,mode_2_msg,mode_3_msg,mode_4_msg
  63.         dw    mode_5_msg,mode_6_msg
  64.  
  65. mode_1_msg    db    "1) Turn off receiver",CR,LF,'$'
  66. mode_2_msg    db    "2) Receive only packets sent to this interface",CR,LF,'$'
  67. mode_3_msg    db    "3) Mode 2 plus broadcast",CR,LF,'$'
  68. mode_4_msg    db    "4) Mode 3 plus limited multicast",CR,LF,'$'
  69. mode_5_msg    db    "5) Mode 3 plus all multicast",CR,LF,'$'
  70. mode_6_msg    db    "6) All packets",CR,LF,'$'
  71.  
  72.  
  73. usage_error:
  74.     mov    dx,offset usage_msg
  75. error:
  76.     mov    ah,9
  77.     int    21h
  78.     jmp    all_done
  79.  
  80. start_1:
  81.     cld
  82.  
  83.     mov    dx,offset copyleft_msg
  84.     mov    ah,9
  85.     int    21h
  86.  
  87.     mov    si,offset phd_dioa+1
  88.     cmp    byte ptr [si],CR    ;end of line?
  89.     je    usage_error
  90.  
  91.     mov    di,offset packet_int_no
  92.     call    get_number
  93.     mov    di,offset packet_mode
  94.     call    get_number
  95.  
  96.     mov    ah,35h            ;get their packet interrupt.
  97.     mov    al,packet_int_no
  98.     int    21h
  99.     mov    their_isr.offs,bx
  100.     mov    their_isr.segm,es
  101.  
  102.     lea    di,3[bx]
  103.     mov    si,offset signature
  104.     mov    cx,signature_len
  105.     repe    cmpsb
  106.     je    signature_ok
  107.     mov    dx,offset no_signature_msg
  108.     jmp    error
  109. bad_j_1:
  110.     jmp    bad
  111. signature_ok:
  112.  
  113.     push    ds
  114.     mov    ax,1ffh            ;driver_info
  115.     int_pkt
  116.     pop    ds
  117.     call    fatal_error
  118.  
  119.     mov    ah,2            ;access all packets.
  120.     mov    al,ch            ;their class from driver_info().
  121.     mov    bx,dx            ;their type from driver_info().
  122.     mov    dl,cl            ;their number from driver_info().
  123.     mov    cx,2            ;use a type length of 2.
  124.     mov    si,offset bogus_type
  125.     push    cs            ;es:di -> our receiver.
  126.     pop    es
  127.     mov    di,offset our_recv
  128.     int_pkt
  129.     call    fatal_error
  130.     mov    handle,ax
  131.  
  132.     mov    cx,packet_mode
  133.     cmp    cx,-1
  134.     je    get_mode
  135.  
  136.     mov    ah,20            ;set the receive mode.
  137.     mov    bx,handle
  138.     int_pkt
  139.     jc    bad_j_1
  140.  
  141.     mov    bx,cx            ;print the name of this mode.
  142.     shl    bx,1
  143.     mov    ah,9
  144.     mov    dx,mode_names[bx-2]
  145.     int    21h
  146.  
  147.     jmp    okay
  148. ;now print the current mode.
  149.  
  150. get_mode:
  151.     mov    ah,21            ;get the receive mode.
  152.     mov    bx,handle
  153.     int_pkt
  154.     jc    bad
  155.     mov    packet_mode,ax
  156.  
  157.     mov    this_mode,1        ;start trying with mode 1.
  158. try_mode:
  159.     cmp    this_mode,6        ;have we hit the last mode?
  160.     ja    no_more_modes        ;yes.
  161.  
  162.     mov    ah,20            ;set the receive mode.
  163.     mov    bx,handle
  164.     mov    cx,this_mode
  165.     int_pkt
  166.     mov    dx,offset not_implemented
  167.     jc    tried_mode        ;we tried it, and it didn't work.
  168.     mov    dx,offset current_mode
  169.     mov    cx,this_mode        ;is this the current mode?
  170.     cmp    packet_mode,cx
  171.     je    tried_mode
  172.     mov    dx,offset two_spaces
  173. tried_mode:
  174.     mov    ah,9            ;print either "  ", "xx", or "->"
  175.     int    21h
  176.  
  177.     mov    bx,this_mode        ;print the name of this mode.
  178.     shl    bx,1
  179.     mov    ah,9
  180.     mov    dx,mode_names[bx-2]
  181.     int    21h
  182.  
  183.     inc    this_mode        ;try the next mode.
  184.     jmp    try_mode
  185.  
  186. no_more_modes:
  187.  
  188.     mov    ah,20            ;set the receive mode.
  189.     mov    bx,handle
  190.     mov    cx,packet_mode
  191.     int_pkt
  192.  
  193. all_done:
  194.     xor    bx,bx            ;only release the handle once.
  195.     xchg    bx,handle
  196.     or    bx,bx
  197.     je    all_done_1        ;we've already released it.
  198.     mov    ah,3            ;release_type
  199.     int_pkt
  200.     jc    bad
  201. all_done_1:
  202.     int    20h
  203.  
  204. bad:
  205.     call    print_error
  206. okay:
  207.     jmp    all_done
  208.  
  209.  
  210. our_recv:
  211.     or    ax,ax            ;first or second call?
  212.     jne    our_recv_1        ;second -- we ignore the packet
  213.     push    cs
  214.     pop    es
  215.     mov    di,offset our_buffer
  216. our_recv_1:
  217.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  218.  
  219.  
  220.     include    getnum.asm
  221.     include    skipblk.asm
  222.     include    getdig.asm
  223.     include    pkterr.asm
  224.     include    chrout.asm
  225.  
  226. our_buffer    label    byte
  227.  
  228. code    ends
  229.  
  230.     end    start
  231.